Skip to content

Add script to generate missing async tests for PGMQOperation using CST#39

Merged
jason810496 merged 7 commits into
ci/add-ast-based-script-for-async-methodsfrom
copilot/sub-pr-36-another-one
Jan 6, 2026
Merged

Add script to generate missing async tests for PGMQOperation using CST#39
jason810496 merged 7 commits into
ci/add-ast-based-script-for-async-methodsfrom
copilot/sub-pr-36-another-one

Conversation

Copilot AI commented Jan 5, 2026

Copy link
Copy Markdown
Contributor

Description

Added scripts/compelete_missing_test_for_operation.py to automatically generate missing async test functions for PGMQOperation class. The script uses libcst for AST-based code transformations, following the same pattern as compelete_missing_async_methods.py.

Changes

  • Main script: scripts/compelete_missing_test_for_operation.py

    • Parses tests/test_operation.py to identify sync tests lacking async counterparts
    • Generates 12 missing async tests through CST transformations
    • Interactive mode with diff preview and confirmation prompt
  • Utility module: scripts/scripts_utils/operation_test_ast.py

    • AsyncTestTransformer: Transforms sync test functions to async
      • Converts withasync with for session context managers
      • Adds await to PGMQOperation method calls and appends _async suffix
      • Replaces get_session_makerget_async_session_maker in parameters and calls
      • Updates docstrings to reflect async semantics
    • TestFunctionVisitor: Collects test functions and identifies missing async tests
    • FillMissingTestsTransformer: Inserts generated tests with @pytest.mark.asyncio decorators

Example Transformation

# Input (sync test)
def test_list_queues_sync(get_session_maker, db_session):
    """Test listing queues."""
    with get_session_maker() as session:
        queues = PGMQOperation.list_queues(session=session, commit=True)

# Generated (async test)
@pytest.mark.asyncio
async def test_list_queues_async(get_async_session_maker, db_session):
    """Test listing queues asynchronously."""
    async with get_async_session_maker() as session:
        queues = await PGMQOperation.list_queues_async(session=session, commit=True)

Status

  • In progress
  • Ready for review
  • Done

Checklist

  • Read the Contributing Guide
  • Passes tests
  • Linted ( we use pre-commit with ruff )
  • Updated documentation

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Add complete missing test for operation using CST approach Add script to generate missing async tests for PGMQOperation using CST Jan 5, 2026
Copilot AI requested a review from jason810496 January 5, 2026 12:03
@jason810496 jason810496 force-pushed the ci/add-ast-based-script-for-async-methods branch from da8aba2 to 9e76606 Compare January 6, 2026 09:25
@jason810496 jason810496 force-pushed the copilot/sub-pr-36-another-one branch from 83cbc9b to 7f6a9c1 Compare January 6, 2026 09:36
jason810496 and others added 7 commits January 6, 2026 17:53
Distinguish sync and async operations in PGMQueue

- Introduced a pre-commit hook to check for missing async methods in PGMQueue.
- Added scripts to identify and generate missing async methods.
- Created utility functions for AST manipulation and method transformation.
- Established configuration for project paths and console output.
* Initial plan

* Refactor AST-based code to use libcst for better code transformation

Co-authored-by: jason810496 <68415893+jason810496@users.noreply.github.com>

* Fix: only wrap call expressions in await, not literals

Co-authored-by: jason810496 <68415893+jason810496@users.noreply.github.com>

* Ask whether to apply change

* Apply missing async methods

* Correct files for check-sync-async-method-for-queue pre-commit

* Add check for operation as well

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: jason810496 <68415893+jason810496@users.noreply.github.com>
Co-authored-by: LIU ZHE YOU <zhu424.dev@gmail.com>
…roach

Co-authored-by: jason810496 <68415893+jason810496@users.noreply.github.com>
…ping

Co-authored-by: jason810496 <68415893+jason810496@users.noreply.github.com>
@jason810496 jason810496 force-pushed the copilot/sub-pr-36-another-one branch from 7f6a9c1 to 86cd6a3 Compare January 6, 2026 10:09
@jason810496 jason810496 marked this pull request as ready for review January 6, 2026 10:10
@jason810496 jason810496 merged commit b8b40cf into ci/add-ast-based-script-for-async-methods Jan 6, 2026
jason810496 added a commit that referenced this pull request Jan 6, 2026
* Add pre-commit hooks and scripts for async method checks in PGMQueue

Distinguish sync and async operations in PGMQueue

- Introduced a pre-commit hook to check for missing async methods in PGMQueue.
- Added scripts to identify and generate missing async methods.
- Created utility functions for AST manipulation and method transformation.
- Established configuration for project paths and console output.

* Refactor code transformation scripts from ast to libcst (#35)

* Initial plan

* Refactor AST-based code to use libcst for better code transformation

Co-authored-by: jason810496 <68415893+jason810496@users.noreply.github.com>

* Fix: only wrap call expressions in await, not literals

Co-authored-by: jason810496 <68415893+jason810496@users.noreply.github.com>

* Ask whether to apply change

* Apply missing async methods

* Correct files for check-sync-async-method-for-queue pre-commit

* Add check for operation as well

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: jason810496 <68415893+jason810496@users.noreply.github.com>
Co-authored-by: LIU ZHE YOU <zhu424.dev@gmail.com>

* Add script to generate missing async methods for PGMQOperation (#37)

* Initial plan

* Add compelete_missing_async_methods_for_operation.py script and operation_ast helper

Co-authored-by: jason810496 <68415893+jason810496@users.noreply.github.com>

* Fix path resolution bug in operation_ast.py

Co-authored-by: jason810496 <68415893+jason810496@users.noreply.github.com>

* Address code review feedback: improve docstring handling and remove unnecessary method

Co-authored-by: jason810496 <68415893+jason810496@users.noreply.github.com>

* Improve docstring handling robustness with better length checks

Co-authored-by: jason810496 <68415893+jason810496@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: jason810496 <68415893+jason810496@users.noreply.github.com>

* Fix queue await error

* Add script to generate missing async tests for PGMQOperation using CST (#39)

* Add pre-commit hooks and scripts for async method checks in PGMQueue

Distinguish sync and async operations in PGMQueue

- Introduced a pre-commit hook to check for missing async methods in PGMQueue.
- Added scripts to identify and generate missing async methods.
- Created utility functions for AST manipulation and method transformation.
- Established configuration for project paths and console output.

* Refactor code transformation scripts from ast to libcst (#35)

* Initial plan

* Refactor AST-based code to use libcst for better code transformation

Co-authored-by: jason810496 <68415893+jason810496@users.noreply.github.com>

* Fix: only wrap call expressions in await, not literals

Co-authored-by: jason810496 <68415893+jason810496@users.noreply.github.com>

* Ask whether to apply change

* Apply missing async methods

* Correct files for check-sync-async-method-for-queue pre-commit

* Add check for operation as well

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: jason810496 <68415893+jason810496@users.noreply.github.com>
Co-authored-by: LIU ZHE YOU <zhu424.dev@gmail.com>

* Initial plan

* Add compelete_missing_test_for_operation.py script with CST-based approach

Co-authored-by: jason810496 <68415893+jason810496@users.noreply.github.com>

* Fix code review feedback: remove redundant code and use Tuple from typing

Co-authored-by: jason810496 <68415893+jason810496@users.noreply.github.com>

* Finalize test_operation

* Fix _check_pg_partman_ext naming

---------

Co-authored-by: LIU ZHE YOU <zhu424.dev@gmail.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: jason810496 <68415893+jason810496@users.noreply.github.com>

* Add script to generate missing async tests using CST transformations (#38)

* Add pre-commit hooks and scripts for async method checks in PGMQueue

Distinguish sync and async operations in PGMQueue

- Introduced a pre-commit hook to check for missing async methods in PGMQueue.
- Added scripts to identify and generate missing async methods.
- Created utility functions for AST manipulation and method transformation.
- Established configuration for project paths and console output.

* Refactor code transformation scripts from ast to libcst (#35)

* Initial plan

* Refactor AST-based code to use libcst for better code transformation

Co-authored-by: jason810496 <68415893+jason810496@users.noreply.github.com>

* Fix: only wrap call expressions in await, not literals

Co-authored-by: jason810496 <68415893+jason810496@users.noreply.github.com>

* Ask whether to apply change

* Apply missing async methods

* Correct files for check-sync-async-method-for-queue pre-commit

* Add check for operation as well

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: jason810496 <68415893+jason810496@users.noreply.github.com>
Co-authored-by: LIU ZHE YOU <zhu424.dev@gmail.com>

* Initial plan

* Add complete_missing_test_for_queue.py script with CST-based approach

Co-authored-by: jason810496 <68415893+jason810496@users.noreply.github.com>

* Apply ruff formatting to test generation scripts

Co-authored-by: jason810496 <68415893+jason810496@users.noreply.github.com>

* Address code review feedback: fix path resolution, type hints, and documentation

Co-authored-by: jason810496 <68415893+jason810496@users.noreply.github.com>

* Fix missing async replacment for compelete test queue

* Fix imports for async fixtures

---------

Co-authored-by: LIU ZHE YOU <zhu424.dev@gmail.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: jason810496 <68415893+jason810496@users.noreply.github.com>

* Unifing script name for queue

* Add missing async test methods for queue, fix check_pg_partman_ext

---------

Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants